
import baseConfig from '@/config'
import { i18n } from '../../lang'
/**
 * @param {axios} axios实例
 * @param {config} 自定义配置对象
 */
export default (axios, config = {}) => {
  const defaultConfig = {
    baseURL: baseConfig.baseUrl,
    timeout: 500,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
      LANG: i18n.global.locale.value.toUpperCase()
    },
    retry: 1, // 接口请求错误时重试次数
    retryDelay: 3000 // 接口请求错误时，重试间隔
  }
  if(localStorage.getItem('token')){
    defaultConfig.headers['Authorization'] = localStorage.getItem('token')
  }
  Object.assign(axios.defaults, defaultConfig, config)
  return axios
}
